﻿
namespace Numbrella.Tracker.Data
{
    using System.Collections.ObjectModel;
    using System.Linq;

    public class OffersQueries
    {
        private readonly DatabaseEntities entities;

        public OffersQueries(DatabaseEntities entities)
        {
            this.entities = entities;
        }

        public ReadOnlyCollection<ProblemOffer> Get(User user, Problem problem)
        {
            var offersQuery = from o in this.entities.ProblemOffers
                              where o.User.Name == user.Name && o.Problem.ID == problem.ID
                              select o;
            
            return offersQuery.ToList().AsReadOnly();            
        }

        public ReadOnlyCollection<ProblemOffer> Get(Problem problem)
        {
            var offersQuery = from o in this.entities.ProblemOffers
                              where o.Problem.ID == problem.ID
                              select o;

            return offersQuery.ToList().AsReadOnly();
        }
    }
}